From: Alexandre Emsenhuber Date: Tue, 7 Aug 2012 06:33:41 +0000 (+0200) Subject: Added WebRequest::getMethod() to get the HTTP method of the request. X-Git-Tag: 1.31.0-rc.0~22820 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=53b3c82fd7c56668b63c6401a699c08f9510bd68;p=lhc%2Fweb%2Fwiklou.git Added WebRequest::getMethod() to get the HTTP method of the request. This is to replace the usage of $_SERVER['REQUEST_METHOD']. Change-Id: I45084254c5452b00b0665df78628cfd214e39cab --- diff --git a/includes/Setup.php b/includes/Setup.php index dedfca9157..518ef6d86e 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -449,7 +449,7 @@ if ( $wgCommandLineMode ) { # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor $wgRequest = new WebRequest; - $debug = "\n\nStart request {$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}\n"; + $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n"; if ( $wgDebugPrintHttpHeaders ) { $debug .= "HTTP HEADERS:\n"; diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 26b943ca60..2cc6338b96 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -563,6 +563,15 @@ class WebRequest { return $_GET; } + /** + * Get the HTTP method used for this request. + * + * @return String + */ + public function getMethod() { + return isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + } + /** * Returns true if the present request was reached by a POST operation, * false otherwise (GET, HEAD, or command-line). @@ -573,7 +582,7 @@ class WebRequest { * @return Boolean */ public function wasPosted() { - return isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST'; + return $this->getMethod() == 'POST'; } /** @@ -1277,6 +1286,10 @@ class FauxRequest extends WebRequest { } } + public function getMethod() { + return $this->wasPosted ? 'POST' : 'GET'; + } + /** * @return bool */ diff --git a/includes/debug/Debug.php b/includes/debug/Debug.php index 0c0052f434..5330a4bbec 100644 --- a/includes/debug/Debug.php +++ b/includes/debug/Debug.php @@ -352,7 +352,7 @@ class MWDebug { 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array( - 'method' => $_SERVER['REQUEST_METHOD'], + 'method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues(),